﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _超市收银系统
{
    //仓库类
    internal class Storehouse
    {
        //List<Fish> fish = new List<Fish>();
        //List<Meat> meat = new List<Meat>();
        //List<Cabbage> cabbage = new List<Cabbage>();
        //List<Banana> banana = new List<Banana>();
        //List<Egg> egg = new List<Egg>();

        // new List<List<WaresFather>>() 就相当于仓库，List<WaresFather> 相当于仓库中的货架
        List<List<WaresFather>> listStorehouse = new List<List<WaresFather>>();

        /// <summary>
        /// 向用户展示货物
        /// </summary>
        public void showGoods()
        {
            foreach (var item in listStorehouse)
            {
                Console.WriteLine("我们仓库有{0}\t,该货物有{1}个\t，每个单位{2}元", item[0].Name, item.Count, item[0].Price);
                //Console.WriteLine("我们仓库有{0}，该货物有{1}个，每个单位{2}元", item[1].Name, item.Count, item[1].Price);
                //Console.WriteLine("我们仓库有{0}，该货物有{1}个，每个单位{2}元", item[2].Name, item.Count, item[2].Price);
                //Console.WriteLine("我们仓库有{0}，该货物有{1}个，每个单位{2}元", item[3].Name, item.Count, item[3].Price);
                //Console.WriteLine("我们仓库有{0}，该货物有{1}个，每个单位{2}元", item[4].Name, item.Count, item[4].Price);
                //break; //跳出循环
            }
        }


        //listStorehouse<0> 存储鱼
        //listStorehouse<1> 存储肉
        //listStorehouse<2> 存储卷心菜
        //listStorehouse<3> 存储香蕉
        //listStorehouse<4> 存储鸡蛋
        /// <summary>
        /// 在创建仓库对象的时候向仓库中添加数据就
        /// </summary>
        public Storehouse()
        {
            listStorehouse.Add(new List<WaresFather>());
            listStorehouse.Add(new List<WaresFather>());
            listStorehouse.Add(new List<WaresFather>());
            listStorehouse.Add(new List<WaresFather>());
            listStorehouse.Add(new List<WaresFather>());
        }

        /// <summary>
        /// 进货
        /// </summary>
        /// <param name="strType">货物的类型</param>
        /// <param name="count">货物的类型的数量</param>
        public void GetGoods(string strType, int count)
        {
            for (int i = 0; i < count; i++)
            {
                switch (strType)
                {
                    case "Fish":
                        listStorehouse[0].Add(new Fish(Guid.NewGuid().ToString(), "鱼", 10, 1000));
                        break;
                    case "Meat":
                        listStorehouse[1].Add(new Meat(Guid.NewGuid().ToString(), "肉", 20, 2000));
                        break;
                    case "Cabbage":
                        listStorehouse[2].Add(new Cabbage(Guid.NewGuid().ToString(), "卷心菜", 6, 500));
                        break;
                    case "Banana":
                        listStorehouse[3].Add(new Banana(Guid.NewGuid().ToString(), "香蕉", 3, 500));
                        break;
                    case "Egg":
                        listStorehouse[4].Add(new Egg(Guid.NewGuid().ToString(), "鸡蛋", 1, 2000));
                        break;
                }
            }
        }

        /// <summary>
        /// 取货
        /// </summary>
        /// <param name="strType">货物的类型名称</param>
        /// <param name="count">货物的类型的数量</param>
        public WaresFather[] SaleGoods(string strType, int count)
        {
            WaresFather[] goods = new WaresFather[count];
            for (int i = 0; i < count; i++)
            {
                switch (strType)
                {
                    case "Fish":
                        goods[i] = listStorehouse[0][0]; //把 List<WaresFather>中的第一个元素赋值给 goods[i]
                        listStorehouse[0].RemoveAt(0); //从仓库的货架中移除第一个元素
                        break;
                    case "Meat":
                        goods[i] = listStorehouse[1][0];
                        listStorehouse[1].RemoveAt(0);
                        break;
                    case "Cabbage":
                        goods[i] = listStorehouse[2][0];
                        listStorehouse[2].RemoveAt(0);
                        break;
                    case "Banana":
                        goods[i] = listStorehouse[3][0];
                        listStorehouse[3].RemoveAt(0);
                        break;
                    case "Egg":
                        goods[i] = listStorehouse[4][0];
                        listStorehouse[4].RemoveAt(0);
                        break;
                }
            }
            return goods;
        }
    }
}
